for k = 3:4
for i = 4: length(trend)
    if(trend(i,k)==0)
       facc = 0;
       his = 1;
       while(trend(i-his,k)==0)
           his =his +1;
       end
       fu = 1;
       while(trend(i+fu,k)==0)
           facc = facc+ ( Stock(i+fu,2)-Stock(i+fu,1) )/Stock(i+fu,1);
           fu = fu+1;
       end
       facc = facc+ ( Stock(i+fu,2)-Stock(i+fu,1) )/Stock(i+fu,1);
       trend(i,k) = (1 + (trend(i+fu,k) - trend(i-his,k))/trend(i-his,k) - facc )*trend(i-his,k);

    end
end
end